package com.lideru.blog.controlle;


import com.lideru.blog.entity.User;
import com.lideru.blog.service.IAdService;
import com.lideru.blog.service.IBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class IndexContrller {

    @Autowired
    private IAdService adService;
    @Autowired
    private IBlogService blogService;

    @RequestMapping("/")
    private String showPage(Model model, HttpSession session){
        model.addAttribute("ad",adService.list());
        model.addAttribute("blog",blogService.list());
        User user = (User) session.getAttribute("user");
        if(user!=null)
            model.addAttribute("user",user);
        else
            model.addAttribute("user",null);

        return "index";
    }
    @RequestMapping("/loginPage")
    private String loginPage( ){
        return "login";
    }


}
